//
//  CodeInputView.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2020/1/9.
//  Copyright © 2020 Mr.Wang. All rights reserved.
//

import UIKit

class SubmitButton: UIButton {
    
    override var intrinsicContentSize: CGSize {
        self.titleLabel?.sizeToFit()
        var size = self.titleLabel?.intrinsicContentSize ?? .zero
        size.width += 20
        return size
    }
    
}

class CodeInputView: UIView {
    
    let textField = UITextField()
    let submitButton = SubmitButton()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = #colorLiteral(red: 0.965619266, green: 0.9657276273, blue: 0.9655568004, alpha: 1)
        self.layer.cornerRadius = 5
        self.layer.masksToBounds = true
        
        submitButton.layer.cornerRadius = 5
        submitButton.layer.masksToBounds = true
        submitButton.setBackgroundImage(UIImage.imageWithColor(APPConfig.baseColor), for: .normal)
        submitButton.setTitleColor(.white, for: .normal)
        submitButton.setTitle("提交".localized, for: .normal)
        submitButton.setContentHuggingPriority(.required, for: .horizontal)
        submitButton.setContentCompressionResistancePriority(.required, for: .horizontal)
        self.addSubview(submitButton)
        submitButton.snp.makeConstraints { (make) in
            make.right.bottom.equalTo(-2)
            make.top.equalTo(2)
        }
        
        textField.setContentCompressionResistancePriority(.required, for: .horizontal)
        textField.backgroundColor = .clear
        textField.placeholder = "手动输入条码...".localized
        self.addSubview(textField)
        textField.snp.makeConstraints { (make) in
            make.left.equalTo(5)
            make.top.bottom.equalToSuperview()
            make.right.equalTo(submitButton.snp.left)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
